<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Calculator extends MX_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 * 	- or -
	 * 		http://example.com/index.php/welcome/index
	 * 	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function Calculator() {
		parent::__construct();
	}
	public function index() {
		$restURL = base_url() . 'calculator/sum/';

		$x = 123;
		$y = 221;

		$restURL .= $x . '/' . $y;

		$xml = simplexml_load_file($restURL);

		echo $xml->value;
	}

	public function sum ()
	{
		$x = $this->uri->segment(3);
		$y = $this->uri->segment(4);
		$result = $this->AddSum($x, $y);
		 
		$dom = new DOMDocument;
		 
		$root = $dom->createElement('result', null);
		 
		$dom->appendChild($root);
		 
		$value = $dom->createElement('value', $result);
		$root->appendChild($value);
		 
		echo $dom->saveXML();
	}

	public function AddSum($a, $b) {
		return $a + $b;
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */